package com.bear.atlassianmcp.jira.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.Map;

/**
 * Jira Project数据模型
 * 对应Jira REST API返回的Project对象
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class JiraProject {

    private String id;
    private String key;
    private String name;
    private String description;
    private String self;
    private Map<String, Object> lead;
    private List<Map<String, Object>> issueTypes;
    private List<Map<String, Object>> versions;
    private List<Map<String, Object>> components;

    /**
     * 获取项目负责人名称
     */
    public String getLeadName() {
        return lead != null ? (String) lead.get("displayName") : null;
    }

    /**
     * 格式化为AI友好的文本描述
     */
    public String toFormattedString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Project: ").append(key).append(" - ").append(name).append("\n");
        sb.append("ID: ").append(id).append("\n");
        
        if (description != null && !description.trim().isEmpty()) {
            sb.append("Description: ").append(description).append("\n");
        }
        
        sb.append("Lead: ").append(getLeadName()).append("\n");
        
        if (issueTypes != null && !issueTypes.isEmpty()) {
            sb.append("Issue Types: ");
            for (int i = 0; i < issueTypes.size(); i++) {
                if (i > 0) sb.append(", ");
                sb.append(issueTypes.get(i).get("name"));
            }
            sb.append("\n");
        }
        
        if (versions != null && !versions.isEmpty()) {
            sb.append("Versions: ");
            for (int i = 0; i < Math.min(versions.size(), 5); i++) { // 只显示前5个版本
                if (i > 0) sb.append(", ");
                sb.append(versions.get(i).get("name"));
            }
            if (versions.size() > 5) {
                sb.append(" (and ").append(versions.size() - 5).append(" more)");
            }
            sb.append("\n");
        }
        
        return sb.toString();
    }

    // Getters and Setters
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSelf() {
        return self;
    }

    public void setSelf(String self) {
        this.self = self;
    }

    public Map<String, Object> getLead() {
        return lead;
    }

    public void setLead(Map<String, Object> lead) {
        this.lead = lead;
    }

    public List<Map<String, Object>> getIssueTypes() {
        return issueTypes;
    }

    public void setIssueTypes(List<Map<String, Object>> issueTypes) {
        this.issueTypes = issueTypes;
    }

    public List<Map<String, Object>> getVersions() {
        return versions;
    }

    public void setVersions(List<Map<String, Object>> versions) {
        this.versions = versions;
    }

    public List<Map<String, Object>> getComponents() {
        return components;
    }

    public void setComponents(List<Map<String, Object>> components) {
        this.components = components;
    }
}
